package com.zhuiYun.project.api.scan;

import com.zhuiYun.project.common.response.CommonResult;
import com.zhuiYun.project.util.RedisUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/scan")
@CrossOrigin
public class Scan {

    @GetMapping("/getScan")
    public CommonResult getScan(String code){
        String url = (String) RedisUtil.get("scanUrl" + code);
        RedisUtil.del("scanUrl"+code);
        return CommonResult.ok(url);
    }
    @GetMapping("/setScan")
    public CommonResult setScan(String code,String url){
        RedisUtil.set("scanUrl"+code,url);
        return CommonResult.ok();
    }
    @GetMapping("/getConnect")
    public CommonResult getConnect(String code){
        String flag = (String) RedisUtil.get("getConnect" + code);
        if(flag==null){
            return CommonResult.ok(false);
        }else{
            RedisUtil.del("getConnect"+code);
            return CommonResult.ok(true);
        }
    }
    @GetMapping("/getCheckConnect")
    public CommonResult getCheckConnect(String code){
        String url = (String) RedisUtil.get("scanUrlConnect" + code);
        if(StringUtils.isNotBlank( url)){
            RedisUtil.del("scanUrlConnect"+code);
            return CommonResult.ok(true);
        }
        return CommonResult.ok(false);
    }
    @GetMapping("/setCheckConnect")
    public CommonResult setCheckConnect(String code){
         RedisUtil.set("scanUrlConnect" + code,"1");
        return CommonResult.ok(true);
    }
    @GetMapping("/setConnect")
    public CommonResult setConnect(String code){
       RedisUtil.set("getConnect" + code,"success");
        return CommonResult.ok();
    }
}
